﻿Imports Logistica.Data
Imports Logistica.Entities

Public NotInheritable Class Producto

    Public Shared Function Listar() As List(Of ProductoBE)
        Dim listado As New List(Of ProductoBE)
        Dim componenteDatos As New ProductoDO


        Try
            listado = componenteDatos.Listar

        Catch ex As Exception
            Throw ex
        Finally
            componenteDatos = Nothing

        End Try

        Return listado
    End Function

    Public Shared Function Registrar(infoProducto As ProductoBE) As Integer
        Dim idRegistro As Integer = 0
        Dim componenteDatos As New ProductoDO

        Try
            If componenteDatos.Obtener(infoProducto).IsEmpty Then
                idRegistro = componenteDatos.Insertar(infoProducto)
            Else

                idRegistro = infoProducto.Id
                componenteDatos.Actualizar(infoProducto)
            End If

        Catch ex As Exception
            Throw ex

        Finally
            componenteDatos = Nothing
        End Try

        Return idRegistro
    End Function

    Public Shared Sub Eliminar(infoProducto)
        Dim componenteDatos As New ProductoDO

        Try
            componenteDatos.Eliminar(infoProducto)

        Catch ex As Exception
            Throw ex

        Finally
            componenteDatos = Nothing
        End Try

    End Sub

    Shared Function Obtener(infoProducto As ProductoBE) As ProductoBE
        Dim componenteDatos As New ProductoDO
        Dim productoRegistrado As New ProductoBE

        Try
            productoRegistrado = componenteDatos.Obtener(infoProducto)

        Catch ex As Exception
            Throw ex
        Finally
            componenteDatos = Nothing

        End Try

        Return productoRegistrado
    End Function

    Public Shared Function RegistrarMovimiento(ByVal infoMovimientoProducto As MovimientoProductoBE) As Integer
        Dim componenteDatos As New ProductoDO
        Dim idRegistro As Integer = 0
        Try
            idRegistro = componenteDatos.RegistrarMovimiento(infoMovimientoProducto)
        Catch ex As Exception
            Throw ex
        Finally
            componenteDatos = Nothing
        End Try

        Return idRegistro
    End Function
End Class
